<?php

namespace App\Http\Controllers;

use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use App\Http\Services\GroupChatMsgServices;
use App\Http\Services\RoomHotServices;
use App\Http\Services\RoomMicroServices;
use App\Http\Services\RoomServicesInit;
use App\Http\Services\RoomTallyServices;
use Illuminate\Http\Request;
use App\Http\Services\GiftBagServices;
use App\Http\Services\MsgServices;
use App\Http\Services\RoomMsgServices;
use App\Http\Services\RoomHostMicroServices;
use App\Http\Services\FinanceServices;
use App\Lib\Response;


class GiftBagController extends Controller
{
    protected $requestObj;// 请求实例类
    protected $requestData = [];// 请求参数
    protected $giftBagServices;
    protected $msgServices;
    protected $roomMsgServices;
    protected $roomHostMicroServices;
    protected $roomMicroServices;
    protected $financeServices;
    protected $roomHotServices;
    protected $serviceRoomTally;
    protected $groupChatMsgServices;






    public function __construct(Request $request, GiftBagServices $giftBagServices, MsgServices $msgServices, RoomMsgServices $roomMsgServices, FinanceServices $financeServices, RoomHotServices $roomHotServices)
    {
        $this->requestObj = $request;
        $this->requestData = $request->post();
        $this->giftBagServices = $giftBagServices;
        $this->msgServices = $msgServices;
        $this->roomMsgServices = $roomMsgServices;
        $this->roomHostMicroServices = RoomServicesInit::createHostMicro();
        $this->roomMicroServices = RoomServicesInit::createMicro();
        $this->financeServices = $financeServices;
        $this->roomHotServices = $roomHotServices;
        $this->serviceRoomTally = new RoomTallyServices();
        $this->groupChatMsgServices = new GroupChatMsgServices();
    }

    /**
     * 响应数据
     * */
    protected function responseData($response = true)
    {
        // 取出调用方法名
        $action = explode('@', $this->requestObj->route()[1]['uses'])[1];

        $data = $this->giftBagServices->$action($this->requestData);

        write_log('giftBag', $action, ['params' => $this->requestData, 'result' => $data]);

        if ($response) {
            OutJson::outJsonResult($data['code'], $data['data']);
        } else {
            return json_encode($data, JSON_UNESCAPED_UNICODE);
        }
    }

    /**
     * 礼物背包
     * */
    public function giftBagList()
    {
        return $this->responseData();
    }

}
